var Clock = _p.Model.extend({
    defaults: {
        datetime: null,
        timer: null
    },
    TIMER_INTERVAL: 1000,
    construct: function() {
        this._superCall();
        this.startTimer();
        this.update();
    },
    startTimer: function() {
        var self = this;
        this.timer = setInterval(function() {
            self.update();
        }, this.TIMER_INTERVAL);
    },
    update: function() {
        this.data.datetime = new Date();
        this.fireEvent("tick");
    },
    satelliteClasses: {
        View: {
            template: $("#template>.clock"),
            defaultSettings: {
                showSeconds: false
            },
            render: function() {
                this._superCall();
                this.showTime();
                if (!this.settings.showSeconds) {
                    $(".seconds", this.el).remove();
                }
            },
            sanitizeNumber: function(number) {
                return (String(number).length < 2) ? "0" + String(number) : String(number);
            },
            showTime: function() {
                $(".hours", this.el).text(this.sanitizeNumber(this.modelData.datetime.getHours()));
                $(".minutes", this.el).text(this.sanitizeNumber(this.modelData.datetime.getMinutes()));
                if (this.settings.showSeconds) {
                    $(".seconds", this.el).text(this.sanitizeNumber(this.modelData.datetime.getSeconds()));
                }
            },
            onModelEvent: function(eventName, info) {
                switch(eventName) {
                    case "tick":
                        this.showTime();
                        break;
                    default:
                        return this._superCall();
                        break;
                }
            }
        }
    }
});